import flet as ft
from ui.file_tools_ui import FileToolsUI
from ui.text_tools_ui import TextToolsUI
from ui.image_tools_ui import ImageToolsUI  # 新增：导入图像工具界面


class ToolboxApp:
    def __init__(self, page):
        self.page = page
        self.setup_ui()

    def setup_ui(self):
        # 工具分类菜单
        self.file_tools_button = ft.ElevatedButton(
            text="文件工具",
            on_click=lambda e: self.show_tool_ui(
                FileToolsUI(self.page, self.show_main_menu)
            ),
        )
        self.text_tools_button = ft.ElevatedButton(
            text="文本工具",
            on_click=lambda e: self.show_tool_ui(
                TextToolsUI(self.page, self.show_main_menu)
            ),
        )
        self.image_tools_button = ft.ElevatedButton(
            text="图像工具",
            on_click=lambda e: self.show_tool_ui(
                ImageToolsUI(self.page, self.show_main_menu)
            ),  # 新增：图像工具按钮
        )

        # 主界面布局
        self.main_menu = ft.Column(
            controls=[
                ft.Text("请选择工具分类：", size=20),
                self.file_tools_button,
                self.text_tools_button,
                self.image_tools_button,  # 新增：图像工具按钮
            ],
            spacing=20,
            alignment=ft.MainAxisAlignment.CENTER,
            horizontal_alignment=ft.CrossAxisAlignment.CENTER,
        )

        # 当前显示的 UI
        self.current_ui = self.main_menu

    def build(self):
        return self.current_ui

    def show_tool_ui(self, tool_ui):
        """显示具体工具界面"""
        self.page.clean()
        self.page.add(tool_ui.build())
        self.page.update()

    def show_main_menu(self):
        """显示主菜单"""
        self.page.clean()
        self.page.add(self.main_menu)
        self.page.update()
